let MonoSingle = require('MonoSingle').default;
var e = require;
var t = module;
var n = exports;
var o,
    i =
        (this && this.__extends) ||
        ((o = function (e, t) {
            return (o =
                Object.setPrototypeOf ||
                ({__proto__: []} instanceof Array &&
                    function (e, t) {
                        e.__proto__ = t;
                    }) ||
                function (e, t) {
                    for (var n in t) Object.prototype.hasOwnProperty.call(t, n) && (e[n] = t[n]);
                })(e, t);
        }),
        function (e, t) {
            function n() {
                this.constructor = e;
            }
            o(e, t), (e.prototype = null === t ? Object.create(t) : ((n.prototype = t.prototype), new n()));
        }),
    r =
        (this && this.__decorate) ||
        function (e, t, n, o) {
            var i,
                r = arguments.length,
                a = r < 3 ? t : null === o ? (o = Object.getOwnPropertyDescriptor(t, n)) : o;
            if ("object" == typeof Reflect && "function" == typeof Reflect.decorate) a = Reflect.decorate(e, t, n, o);
            else
                for (var s = e.length - 1; 0 <= s; s--)
                    (i = e[s]) && (a = (r < 3 ? i(a) : 3 < r ? i(t, n, a) : i(t, n)) || a);
            return 3 < r && a && Object.defineProperty(t, n, a), a;
        },
    a =
        (this && this.__awaiter) ||
        function (e, a, s, c) {
            return new (s = s || Promise)(function (n, t) {
                function o(e) {
                    try {
                        r(c.next(e));
                    } catch (e) {
                        t(e);
                    }
                }
                function i(e) {
                    try {
                        r(c.throw(e));
                    } catch (e) {
                        t(e);
                    }
                }
                function r(e) {
                    var t;
                    e.done
                        ? n(e.value)
                        : ((t = e.value) instanceof s
                              ? t
                              : new s(function (e) {
                                    e(t);
                                })
                          ).then(o, i);
                }
                r((c = c.apply(e, a || [])).next());
            });
        },
    s =
        (this && this.__generator) ||
        function (n, o) {
            var i,
                r,
                a,
                s = {
                    label: 0,
                    sent: function () {
                        if (1 & a[0]) throw a[1];
                        return a[1];
                    },
                    trys: [],
                    ops: []
                },
                e = {next: t(0), throw: t(1), return: t(2)};
            return (
                "function" == typeof Symbol &&
                    (e[Symbol.iterator] = function () {
                        return this;
                    }),
                e
            );
            function t(t) {
                return function (e) {
                    return (function (t) {
                        if (i) throw new TypeError("Generator is already executing.");
                        for (; s; )
                            try {
                                if (
                                    ((i = 1),
                                    r &&
                                        (a =
                                            2 & t[0]
                                                ? r.return
                                                : t[0]
                                                ? r.throw || ((a = r.return) && a.call(r), 0)
                                                : r.next) &&
                                        !(a = a.call(r, t[1])).done)
                                )
                                    return a;
                                switch (((r = 0), (t = a ? [2 & t[0], a.value] : t)[0])) {
                                    case 0:
                                    case 1:
                                        a = t;
                                        break;
                                    case 4:
                                        return s.label++, {value: t[1], done: !1};
                                    case 5:
                                        s.label++, (r = t[1]), (t = [0]);
                                        continue;
                                    case 7:
                                        (t = s.ops.pop()), s.trys.pop();
                                        continue;
                                    default:
                                        if (
                                            !(a = 0 < (a = s.trys).length && a[a.length - 1]) &&
                                            (6 === t[0] || 2 === t[0])
                                        ) {
                                            s = 0;
                                            continue;
                                        }
                                        if (3 === t[0] && (!a || (t[1] > a[0] && t[1] < a[3]))) {
                                            s.label = t[1];
                                            break;
                                        }
                                        if (6 === t[0] && s.label < a[1]) {
                                            (s.label = a[1]), (a = t);
                                            break;
                                        }
                                        if (a && s.label < a[2]) {
                                            (s.label = a[2]), s.ops.push(t);
                                            break;
                                        }
                                        a[2] && s.ops.pop(), s.trys.pop();
                                        continue;
                                }
                                t = o.call(n, s);
                            } catch (e) {
                                (t = [6, e]), (r = 0);
                            } finally {
                                i = a = 0;
                            }
                        if (5 & t[0]) throw t[1];
                        return {value: t[0] ? t[1] : void 0, done: !0};
                    })([t, e]);
                };
            }
        };
Object.defineProperty(n, "__esModule", {value: !0});
var c,
    l = e("index"),
    u = e("events"),
    p = e("sound"),
    h = e("cell-layer"),
    d = e("player-info"),
    f = e("player-theme"),
    m = e("player-war"),
    y = e("war-cell-layer"),
    g = e("guide-manager"),
    t = cc._decorator,
    e = t.ccclass,
    t = t.property,
    e =
        ((c = cc.Component),
        i(v, c),
        (v.prototype.start = function () {
            u.operEvent.on(this.onOperTap.bind(this)),
                (this.moveHeight = this.node.parent.height),
                (this.moveWidth = this.node.parent.width);
        }),
        (v.prototype.onOperTap = function (e) {
            this.isOffOpenEvent
                ? console.log("isOffOpenEvent...", this.isOffOpenEvent)
                : null != e || null != e.action
                ? d.playerInfo.getGameType() === d.gameType.nomal && null != this.curCellLayer
                    ? this.onOperCall(e)
                    : d.playerInfo.getGameType() === d.gameType.war &&
                      null != this.curWarCellLayer &&
                      this.onOperWarCall(e)
                : console.error("onOperTap error data:", e);
        }),
        (v.prototype.onOperWarCall = function (e) {
            switch (e.action) {
                case u.default.cellTouch:
                    this.curWarCellLayer.chooseCell(e.data.cellIdx, e.data.isChoose);
                    break;
                case u.default.cellAdsLock:
                    this.curWarCellLayer.unlockAdsCell(e.data.cellIdx);
                    break;
                case u.default.recoveryCoin:
                    this.curWarCellLayer.recoveryCoin(e.data.coin);
                    break;
                case u.default.restartCellLayer:
                    (this.isOffOpenEvent = !0), this.cloneWarCellLayer(this.moveWidth, 0);
            }
        }),
        (v.prototype.onOperCall = function (e) {
            var t = this;
            switch (e.action) {
                case u.default.cloneCellLayer:
                    this.isOffOpenEvent = !0;
                    var n = (null != e.data.cellDelayTime ? e.data : this).cellDelayTime;
                    this.scheduleOnce(function () {
                        t.cloneCellLayer(0, t.moveHeight);
                    }, n);
                    break;
                case u.default.cellTouch:
                    this.curCellLayer.chooseCell(e.data.cellIdx, e.data.isChoose);
                    break;
                case u.default.merge:
                    this.curCellLayer.merge();
                    break;
                case u.default.deal:
                    n = !1;
                    e.data && e.data.guide && (n = e.data.guide), this.curCellLayer.deal(n);
                    break;
                case u.default.add10Max:
                    this.curCellLayer.deal10Max();
                    break;
                case u.default.cellAdsLock:
                    this.curCellLayer.unlockAdsCell(e.data.cellIdx);
                    break;
                case u.default.shuffle:
                    this.curCellLayer.shuffle();
                    break;
                case u.default.cellNext:
                    this.curCellLayer.cellNext(e.data.cellIdx);
                    break;
                case u.default.checkShuffle:
                    this.curCellLayer.checkShuffle();
                    break;
                case u.default.adsCanUnlock:
                    this.curCellLayer.showOneAdsCanUnlock(!0);
                    break;
                case u.default.restartCellLayer:
                    (this.isOffOpenEvent = !0), this.cloneCellLayer(this.moveWidth, 0);
                    break;
                case u.default.recoveryCoin:
                    this.curCellLayer.recoveryCoin(e.data.coin);
            }
        }),
        (v.prototype.cloneCellLayer = function (e, t) {
            var n,
                o,
                i = this;
            this.curCellPrefab && this.curCellLayer
                ? (g.GuideManager.ins.setIsNeedCheck(!1),
                  ((n = cc.instantiate(this.curCellPrefab)).parent = this.cellParent),
                  n.setPosition(e, t),
                  (n.opacity = this.moveEndOpacity),
                  cc
                      .tween(n)
                      .to(0, {opacity: 255, y: 0, x: 0})
                      .call(function () {
                          (i.curCellLayer = n.getComponent(h.default)),
                              u.operEvent.emit({action: u.default.nextLevel, data: {}}),
                              (i.isOffOpenEvent = !1),
                              g.GuideManager.ins.setIsNeedCheck(!0),
                              i.curCellLayer.checkAllGuide();
                      })
                      .start(),
                  (o = this.curCellLayer.node),
                  cc
                      .tween(o)
                      .to(0, {opacity: this.moveEndOpacity, x: -e, y: -t})
                      .call(function () {
                          o.removeFromParent(), o.destroy();
						  MonoSingle.GetTvBoxInput().refreshPanel(0.1)
                      })
                      .start(),
                  p.sound.play(p.Sound.RENEWAREA))
                : console.log("error cloneCellLayer");
        }),
        (v.prototype.loadCellLayer = function () {
            return a(this, void 0, void 0, function () {
                var t, n;
                return s(this, function (e) {
                    switch (e.label) {
                        case 0:
                            return (
                                (n = f.playerTheme.getCurThemeName()),
                                [4, l.ResUtil.loadPrefab("prefab/prefab/" + n + "/cell-layer")]
                            );
                        case 1:
                            return (
                                (t = e.sent()),
                                ((n = cc.instantiate(t)).parent = this.cellParent),
                                n.setPosition(0, 0),
                                (this.curCellPrefab = t),
                                (this.curCellLayer = n.getComponent(h.default)),
                                [2]
                            );
                    }
                });
            });
        }),
        (v.prototype.cloneWarCellLayer = function (e, t) {
            var n = cc.instantiate(this.curWarCellPrefab);
            (n.parent = this.cellParent),
                n.setPosition(e, t),
                (n.opacity = this.moveEndOpacity),
                this.moveWarCellLayer(n, this.curWarCellLayer.node, e, t, function () {});
        }),
        (v.prototype.moveWarCellLayer = function (n, e, t, o, i) {
            var r = this;
            cc
                .tween(n)
                .to(this.moveDelayTime, {opacity: 255, y: 0, x: 0})
                .call(function () {
                    (r.curWarCellLayer = n.getComponent(y.default)), (r.isOffOpenEvent = !1);
                    var e = m.playerWar.getWarLevel(),
                        t = m.playerWar.getIsGuideLevel();
                    (0 == e && !t) || u.operEvent.emit({action: u.default.restartWarTime, data: {}}),
                        r.curWarCellLayer.dealCoins();
                })
                .start(),
                cc
                    .tween(e)
                    .to(this.moveDelayTime, {opacity: this.moveEndOpacity, x: -t, y: -o})
                    .call(function () {
                        e.removeFromParent(), e.destroy(), i();
                    })
                    .start();
        }),
        (v.prototype.loadWarCellLayer = function () {
            return a(this, void 0, void 0, function () {
                var t, n;
                return s(this, function (e) {
                    switch (e.label) {
                        case 0:
                            return [4, l.ResUtil.loadPrefab("prefab/prefab/war/war-cell-layer")];
                        case 1:
                            return (
                                (t = e.sent()),
                                ((n = cc.instantiate(t)).parent = this.cellParent),
                                n.setPosition(0, 0),
                                (this.curWarCellPrefab = t),
                                (this.curWarCellLayer = n.getComponent(y.default)),
                                this.curWarCellLayer.setIsCanDeal(!0),
                                [2]
                            );
                    }
                });
            });
        }),
        r([t(cc.Node)], v.prototype, "cellParent", void 0),
        r([t({displayName: "cell延时移动时间"})], v.prototype, "cellDelayTime", void 0),
        r([t({displayName: "cell移动时间"})], v.prototype, "moveDelayTime", void 0),
        r([t({displayName: "cell移动结束的透明度"})], v.prototype, "moveEndOpacity", void 0),
        r([e], v));
function v() {
    var e = (null !== c && c.apply(this, arguments)) || this;
    return (
        (e.cellParent = null),
        (e.cellDelayTime = 0),
        (e.moveDelayTime = 0),//神道烨
        (e.moveEndOpacity = 10),
        (e.curCellLayer = null),
        (e.curCellPrefab = null),
        (e.moveHeight = 0),
        (e.moveWidth = 0),
        (e.isOffOpenEvent = !1),
        (e.curWarCellLayer = null),
        (e.curWarCellPrefab = null),
        e
    );
}
n.default = e;
